<template>
	<el-dialog title="资产申请对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="80px" label-position="left">
			<el-form-item label="申请标题" prop="title">
				<el-input v-model="form.title" clearable placeholder="申请标题" maxlength="80"></el-input>
			</el-form-item>
			<el-form-item label="资产名称">{{ assetsName }}</el-form-item>
			<el-form-item label="资产编号">{{ assetsCode }}</el-form-item>
			<el-form-item label="品牌">{{ brand }}</el-form-item>
			<el-form-item label="型号">{{ model }}</el-form-item>
			<el-form-item label="使用人" prop="usedUser">
				<select-user-dialog v-model:accountId="form.usedUser" :mode="false"/>
			</el-form-item>
			<el-form-item label="使用部门" prop="usedDept">
				<select-dept-dialog v-model:deptId="form.usedDept" :mode="false"/>
			</el-form-item>
			<el-form-item label="备注说明">
				<el-input v-model="form.remark" type="textarea" placeholder="备注说明" maxlength="180" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import selectDeptDialog from "@/views/module/selectDeptDialog";

export default {
	components: {
		selectUserDialog,
		selectDeptDialog
	},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			assetsId: '',
			assetsName: '',
			assetsCode: '',
			brand: '',
			model: '',
			form: {
				assetsId:'',
				title: "",
				usedUser: "",
				usedDept: "",
				remark: ""
			},
			rules: {
				title: [
					{required: true, message: '申请标题不能为空！'}
				],
				usedUser: [
					{required: true, message: '请选择使用人！'}
				],
				usedDept: [
					{required: true, message: '请选择使用部门！'}
				]
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.office.fixed.insertFixedAssetsApply.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.assetsId = data.assetsId
			this.form.assetsId = data.assetsId
			this.assetsName = data.assetsName
			this.assetsCode = data.assetsCode
			this.brand = data.brand
			this.model = data.model
			this.assetsCode = data.assetsCode
		}
	}
}
</script>

<style>
</style>
